//package com.ruoyi.quartz.edh;
//
//import com.ruoyi.common.utils.DateUtils;
//import com.ruoyi.edh.domain.EdhCoupon;
//import com.ruoyi.edh.domain.EdhCouponLog;
//import com.ruoyi.edh.service.IEdhCouponLogService;
//import com.ruoyi.edh.service.IEdhCouponService;
//import lombok.extern.log4j.Log4j2;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//
//import java.util.Calendar;
//import java.util.Date;
//import java.util.List;
//
//@Configuration
//@EnableScheduling
//@Log4j2
//public class CouponLogQuartz {
//    @Autowired
//    private IEdhCouponLogService edhCouponLogService;
//    @Autowired
//    private IEdhCouponService couponService;
//
//    @Scheduled(cron = "0/60 * * * * ?")
//    private void couponLogExpired() {
//        List<EdhCouponLog> edhCouponLogs = edhCouponLogService.queryNotExpiredUserCoupon();
//        for (EdhCouponLog edhCouponLog : edhCouponLogs) {
//            try {
//                //当前时间大于优惠卷最后使用时间
//                if (System.currentTimeMillis()> DateUtils.getLater(edhCouponLog.getUseEndTime(),1, Calendar.DATE).getTime())
//                {
//                 edhCouponLogService.updateExpiredUserCoupon(edhCouponLog.getId().toString());
//                 log.info("优惠卷id"+edhCouponLog.getId()+"失效状态修改成功");
//                }
//            }catch (Exception e){
//                log.error("优惠卷自动失效发生异常");
//            }
//        }
//    }
//
//    @Scheduled(cron = "0/60 * * * * ?")
//    private void couponExpired() {
//        List<EdhCoupon> edhCoupons = couponService.selectExpiredCoupon();
//        for (EdhCoupon edhCoupon : edhCoupons) {
//            try {
//                EdhCoupon coupon=new EdhCoupon();
//                coupon.setId(edhCoupon.getId());
//                long time = System.currentTimeMillis();
//                //当前时间大于优惠卷最后使用时间
//               if (edhCoupon.getSendStartTime().getTime()<time){
//                   System.out.println(edhCoupon.getSendStartTime().getTime());
//                   System.out.println(edhCoupon.getSendStartTime());
//                   coupon.setStatus(2);
//               }else if(edhCoupon.getSendEndTime().getTime()<time){
//                   coupon.setStatus(4);
//                }
//                couponService.updateExpiredCoupon(coupon.getStatus().toString(),coupon.getId().toString());
//                log.info("优惠卷状态修改成功"+coupon.toString());
//            }catch (Exception e){
//                log.error("优惠卷状态发生异常");
//            }
//        }
//    }
//}
